#-*- coding: utf-8 -*-
# 对抗12306多次查询后,会出现服务器繁忙问题
'''
@createDate 2018-01-16
@author: minjie.qu
@version: 1.0 beta

'''

from autotrainticket.trainticket import login,search,book
import configparser

config=configparser.ConfigParser()
config.read('user.cfg')

result = 'starton'
username=config.get('user','username')
password=config.get('user','password')
begin_hour = 15
begin_minute = 12
begin_second = 0
refresh_interval = 0.5
timer=False #为True启动定时刷新,启动时间为15:12:00
train_type='Z'

for i in range(1,5):
    if result == 'starton':
        try:
            sel = login(username,password)
            if timer == True:
                search(sel, train_type, timer, begin_hour, begin_minute, begin_second)
            else:
                search(sel, train_type, timer)   
            book(sel,refresh_interval)
        except:
            continue
    else:
        print (result)
        break
